/***********************************************************************
    Written By Alex "SparkyMcSparks" Romo
    
    Questions? Concerns? Suggestions?
        Contact Me On AIM @ DareDevilSparks7
***********************************************************************/

Script.Load( "lua/Utility.lua" )
Script.Load( "lua/Sparks_Tools.lua" )

class 'Galaga_TargetFire' ( Actor )

Galaga_TargetFire.modelName  = "models/system/editor/ambient_sound.model"

Galaga_TargetFire.extents   = Vector(0.4064, 0.7874, 0.4064)
Galaga_TargetFire.moveSpeed  =  5

Shared.PrecacheModel( Galaga_TargetFire.modelName )

Galaga_TargetFire.State = enum { 'MoveIn', 'Killed' }

Galaga_TargetFire.thinkInterval = 0.18 // 0.25
Galaga_TargetFire.networkVars = 
    {

    }
    
function Galaga_TargetFire:OnInit()
    Actor.OnInit( self )
    
    self.type = 0
    
    self.velocity = Vector( 0, 0, 0 )
    
    self:SetModel( Galaga_TargetFire.modelName )
    
    self.moveGroupMask              = 0xFFFFFFFD
    
    if ( Client ) then
        // Blank -- Nothing On The Client Side So Far
    end
    
    if ( Server ) then
        //self.state  = Galaga_TargetFire.State.MoveIn
        
        self:SetNextThink( Galaga_TargetFire.thinkInterval )
    end
    
end

function Galaga_TargetFire:OnLoad()
    Actor.OnLoad( self )
end

function Galaga_TargetFire:GetCanMove()
    return Game.instance:GetHasGameStarted()
end

function Galaga_TargetFire:Fire( target )
    local org = Vector( target:getOrigin() )
    // Sparks: TODO -- Initiate Movement Here
end

function Galaga_TargetFire:checkColliding()
    // Sparks: TODO -- Check If Bullet Intersecting With Player(s)
end

function Galaga_TargetFire:checkBounds()
    // Sparks: TODO -- Check If Bullet Is Off Screen Then Kill It
    
    Server.DestroyEntity( self )
end

if ( Server ) then
    function Galaga_TargetFire:DealDamage()        
        self.state = Galaga_Target.State.Killed
        
        Server.DestroyEntity( self )
    end

    function Galaga_TargetFire:OnThink()
        Actor.OnThink( self )
        
        local time = Shared.GetTime()
        
        if ( self.state == Galaga_Target.State.Killed ) then
             // Nothing Yet
        else
            self:MoveIn()
        end
        
        self:SetNextThink( Galaga_Target.thinkInterval )
    end 
end

if ( Client ) then
    function Galaga_TargetFire:DealDamage() 
        if( self.model ~= nil ) then
            Client.DestroyRenderModel( self.model )
            self.model = nil
        end
    end

    function Galaga_Target:OnSynchronized()
        Actor.OnSynchronized( self )
    end
end

Shared.LinkClassToMap( "Galaga_TargetFire", "galaga_targetfire", Galaga_TargetFire.networkVars )